import { forwardRef, useImperativeHandle, useState } from 'react';

// 使用 forwardRef 包裹子组件
const Children = forwardRef((props, ref) => {
  const [obj, setobj] = useState({ name: 'zhangsan', age: 18 });

  // 子组件的内部方法
  const handleChildren = () => {
    console.log('Children Page');
    return 'Hello from Children!'; // 可选返回值
  };

  // 使用 useImperativeHandle 暴露方法
  useImperativeHandle(ref, () => ({
    handleChildren,
  }));

  return (
    <div>
      <h1>Children Page</h1>
    </div>
  );
});

export default Children;
